package singleton.dcl;

public class Singleton {
    // volatile 保证多线程环境下的可见性
    private static volatile Singleton INSTANCE = null;
    private Singleton(){

    }
    public static Singleton getInstance(){
        // 调用时创建实例
        if (INSTANCE == null){
            synchronized (Singleton.class){
                if (INSTANCE == null){
                    INSTANCE = new Singleton();
                }
            }
        }
        return INSTANCE;
    }
}
